<?php
include_once("controller.php");

/*
function dispalyContent($route){
	//getting content
	include($route);
	return $content;
}*/

function displayDefault($route){//create page with default template
	$content_path = $route;	//getting content
	include(templates_folder . default_template);//applaying in template
}

function displayTemplated($route){//create page with template
	include($route . CFG);//read config
	
	if(file_exists(templates_folder . $template)){//check if template is exist
		/*if(isset($module) && $module!=""){//if page using module
			LoadModule($module);
		}
		else{
			$content_path = $route . CNT;	//getting content
			include(templates_folder . $template);//applaying in template
		}*/
		if(isset($module) && $module!=""){//if page using module
			LoadModule($module);
		}
		$content_path = $route . CNT;	//getting content
		include(templates_folder . $template);//applaying in template
	}
	else{
		displayDefault($route . CNT);
	}
}

function displayError($error, $route = null){
	if(errors){
		displayDefault(errors_folder . $error .".php");
	}
}

function displayResult(){
//display some result
}

function loadObjects($object_name){
	if(objects){
		if(file_exists(objects_folder . $object_name . ".php")){
			include(objects_folder . $object_name . ".php");
		}
		else{
			echo "No such object '". $object_name ."' in ". objects_folder ." folder";
		}
	}
	else{
		echo "Objects are currently disabled";
	}
}

function LoadModule($module_name){
	if(modules){
		/*if(file_exists(modules_core_folder . $module_name . DIRSEP . "view.php") && file_exists(modules_core_folder . $module_name . DIRSEP . "model.php") && file_exists(modules_core_folder . $module_name . DIRSEP . "controller.php")){
			echo "Successfully loaded core module '". $module_name ."'";
		}
		elseif(file_exists(modules_folder . $module_name . DIRSEP . "view.php") && file_exists(modules_folder . $module_name . DIRSEP . "model.php") && file_exists(modules_core_folder . $module_name . DIRSEP . "controller.php")){
			echo "Successfully loaded module '". $module_name ."'";
		}
		else{
			echo "Failed to load module '". $module_name ."'";
		}
		include(modules_core_folder . $module_name . DIRSEP . "view.php");
		include(modules_core_folder . $module_name . DIRSEP . "model.php");
		include(modules_core_folder . $module_name . DIRSEP . "controller.php");*/
		if(file_exists(modules_folder . $module_name . DIRSEP . "functions.php")){
			//echo "Successfully loaded module '". $module_name ."'";
			include(modules_folder . $module_name . DIRSEP . "functions.php");
		}
		else{
			echo "Failed to load module '". $module_name ."'<br>
			No such file '". modules_folder . $module_name . DIRSEP . "functions.php" ."'";
		}
	}
	else{
		echo "Modules are currently disabled";
	}
}
?>
